package com.sx.zongzhi.presenter;

import com.sx.zongzhi.MyApplication;
import com.sx.zongzhi.bean.KeyAreaDetailBean;
import com.sx.zongzhi.modle.ApiManager;
import com.sx.zongzhi.net.BaseCallBack;
import com.sx.zongzhi.net.BaseResult;
import com.sx.zongzhi.view.IKeyAreaAddView;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by XZY on 2017/11/30.
 *重点区域添加/更新
 */
public class KeyAreaAddPest {

    private IKeyAreaAddView areaAddView;

    public KeyAreaAddPest(IKeyAreaAddView areaAddView) {
        this.areaAddView=areaAddView;
    }


    /**
     *
     * @param path 地址类型
     * @param id 重点区域id
     * @param detailBean
     */
    public void AddKeyArea(String path,String id,String orgId,KeyAreaDetailBean detailBean,String url){
        Map<String,Object> map=new HashMap<>();
        map.put("sid", MyApplication.sid);
        map.put("importantArea.id", id);//区域id
        map.put("importantArea.organization.id", orgId);//网格
        map.put("importantArea.name",detailBean.getName());
        map.put("importantArea.type.id", detailBean.getType().getId());
        map.put("importantArea.nativePolice", detailBean.getNativePolice());
        map.put("importantArea.address", detailBean.getAddress());
        map.put("importantArea.leader",  detailBean.getLeader());
        map.put("importantArea.telephone",  detailBean.getTelephone());
        map.put("importantArea.mobile",  detailBean.getMobile());
        map.put("importantArea.hasDanger",  detailBean.isHasDanger());
        map.put("importantArea.dangerDes",  detailBean.getDangerDes());
        map.put("importantArea.treatDanger",  detailBean.getTreatDanger());
        map.put("importantArea.remark",  detailBean.getRemark());
        map.put("importantArea.attentionExtent.id",  detailBean.getAttentionExtent()!=null?
                detailBean.getAttentionExtent().getId():"");
        map.put("importantArea.imgUrl",  url);
        new ApiManager().AddKeyArea(path,map, new BaseCallBack<BaseResult<Boolean>>() {
            @Override
            public void onSuccess(BaseResult<Boolean> response) {
                areaAddView.addSuccess(response.getData());
            }
            @Override
            public void onFailures(String message) {
                areaAddView.showError(message);
            }
        });
    }

    /**
     * 判断是否有相同的名称
     * @param path 地址类别
     * @param orgId 网格id
     * @param name 名称
     * @param id (建议新增时不提交,更新时提交当前更改重点区域id)
     */
    public void keyAreaName(String path,String orgId,String name,String id){
        Map<String,Object> map=new HashMap<>();
        map.put("sid", MyApplication.sid);
        map.put("importantArea.organization.id", orgId);//网格
        map.put("importantArea.name",name);
        map.put("importantArea.id", id);//区域id
        new ApiManager().AddKeyArea(path,map, new BaseCallBack<BaseResult<Boolean>>() {
            @Override
            public void onSuccess(BaseResult<Boolean> response) {
                areaAddView.nameSuccess(response.getData());
            }
            @Override
            public void onFailures(String message) {
                areaAddView.showError(message);
            }
        });
    }

}
